import 'package:flutter/material.dart';
import 'package:flutter_vant/component/overlay.dart';
import 'package:flutter_vant/component/toastView.dart';

enum VanToastType {
  success,
  fail,
  loading,
  html,
}

enum VanToastPosition { top, middle, bottom }

class VanToastOption {
  // 图标
  final dynamic icon;
  // 提示消息
  final String? message;
  // 提示类型
  VanToastType? type;
  // 提示延迟
  final Duration duration;
  // 提示位置
  final VanToastPosition position;
  // 是否显示遮挡
  final bool? overlay;
  // 完全展示后的回调函数
  final dynamic onOpened;
  // 关闭时的回调函数
  final dynamic onClose;
  // 是否在点击遮罩层后关闭
  final bool? closeOnClickOverlay;
  // 样式
  final Map<String, dynamic>? styles;
  VanToastOption({
    this.icon,
    this.message,
    this.type,
    this.styles = const {},
    this.duration = const Duration(milliseconds: 2000),
    this.position = VanToastPosition.middle,
    this.overlay = false,
    this.onOpened,
    this.onClose,
    this.closeOnClickOverlay,
  });
}

class VanToast {
  VanToast(BuildContext context, VanToastOption? option) {
    createToast(context, option ?? VanToastOption(type: VanToastType.html));
  }
  // ignore: non_constant_identifier_names
  Toast({required BuildContext context, VanToastOption? option}) {
    createToast(context, option ?? VanToastOption());
  }

  static createToast(BuildContext context, VanToastOption? option) {
    // VanOverlay.show(
    //     context: context,
    //     child: VanToastView(
    //       option: option ?? VanToastOption(),
    //     ));
  }

  static fail(BuildContext context, VanToastOption option) {
    option.type = VanToastType.fail;
    createToast(context, option);
  }

  static success(BuildContext context, VanToastOption option) {
    option.type = VanToastType.success;
    createToast(context, option);
  }

  static loading(BuildContext context, VanToastOption option) {
    option.type = VanToastType.loading;
    createToast(context, option);
  }
}
